#include "named_pipe.hpp"

// 写一次
void WriteMessageOnce(NamedPipe &fifo)
{
    std::string msg;
    std::cout << "Please Enter> " << std::endl;
    std::getline(std::cin, msg);
    fifo.WriteNamePipe(msg);
}

// 写消息
void WriteMessage(NamedPipe &fifo, int times = -1)
{
    if (times == -1)
    {
        while (true)
        {
            WriteMessageOnce(fifo);
        }
    }
    else
    {
        while (times--)
        {
            WriteMessageOnce(fifo);
        }
    }
}

// write
int main()
{
    NamedPipe fifo(comm_path, User);
    if (fifo.OPenForWrite())
    {
        // 写消息
        WriteMessage(fifo);
    }

    return 0;
}